package com.xiaobai.units;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.jsoup.Jsoup;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: 小白白
 * @create: 2021-09-24
 **/

public class Test {
    /**
     *  图像识别
     * @throws IOException
     * 注意: maven依赖
     *           < dependency>
     *             < groupId>org.jsoup< /groupId>
     *             < artifactId>jsoup< /artifactId>
     *             < version>1.11.3< /version>
     *         < /dependency>
     *
     */
    public static void main(String[] args) throws IOException {

        //用户名
        String username= "13723574890";
        //密码
        String password= "1111qqqq";
        //备注字段: 可以不写
        String remark="输出计算结果";

        Map< String, String> data = new HashMap<>();
        data.put("username",username);
        data.put("password", password);
        //一、图片文字类型(默认 3 数英混合)：
        //1 : 纯数字
        //1001：纯数字2
        //2 : 纯英文
        //1002：纯英文2
        //3 : 数英混合
        //1003：数英混合2
        //4 : 闪动GIF
        //7 : 无感学习(独家)
        //11 : 计算题
        //1005:  快速计算题
        //16 : 汉字
        //32 : 通用文字识别(证件、单据)
        //66:  问答题
        //49 :recaptcha图片识别 参考 https://shimo.im/docs/RPGcTpxdVgkkdQdY
        //二、图片旋转角度类型：
        //29 :  旋转类型

        //三、图片坐标点选类型：
        //19 :  1个坐标
        //20 :  3个坐标
        //21 :  3 ~ 5个坐标
        //22 :  5 ~ 8个坐标
        //27 :  1 ~ 4个坐标
        //48 : 轨迹类型
        //四、缺口识别
        //18：缺口识别
        //五、拼图识别
        //53：拼图识别
        data.put("typeid", "3");
//        data.put("remark", remark);
        data.put("image", "/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAeAGwDAS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4iaRb2wcmOIgfckDdD7g4PbPJHVVn6Pp9zptkba51OfUMOfLluFUOqYACkgDceD8x5Oa0D045Nc1aUZSvFJel7fiXFNLUgub20slVrq6hgVjhTLIFyfbNTAggEHIPQivLdHGhaxYanc+KLkDVRI4YzSlHjXHARc84OeAD6Yrb+HOs28mixaZNfRtdqzmOE5DBOuORz3PGeK8+niueSTtZ7a/mejWwThBtXbjvpp8juKKKK6zgKuo2Zv8AT57QTPD5qld6dR/9aoNF0iHRtOS1iO5vvSSYxvb1rRoqeVc3N1I9nFz9pbXYKKKKosr39ol/p9zZyHCTxNGSO2RjNYvgrTtR0rw6lnqSKkkcjeWqsGwh55I46lq6KiodNOan1RoqslTdPo9QrA8LeErDwlbXUNi80puJvNeWcgueAACQBkDk/wDAjW/RWyqSjFwT0e/yMrJu4UUUVAzzzxnBZWnjDR7y/s4hpzkmZ1jGXfP8f94D5Tg9s1Fr8em3vifQ4/DYtmu0l3yvaKCqoCuCxXjjn/JFegXthaajbNb3lvHPCedrjPPqPQ+9MsNLsdLh8qxtYrdDjOxcFvqep/GuOWGbk9rN38z0IYxRhHe8U15a9y3RRRXYeef/2Q==");

        String resultString = Jsoup.connect("http://api.ttshitu.com/predict")
                .requestBody(JSON.toJSONString(data))
                .header("Content-Type", "application/json")
                .ignoreContentType(true).timeout(120000).post().text();
        JSONObject jsonObject = JSONObject.parseObject(resultString);
        if (jsonObject.getBoolean("success")) {
            String result=jsonObject.getJSONObject("data").getString("result");
            System.out.println("识别成功结果为:"+result);
        }else {
            System.out.println("识别失败原因为:"+jsonObject.getString("message"));
        }
    }
}
